package com.znsb.msfq.utils;


import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by yg846 on 2016/8/9.
 */
public class JsonResult {
    //code
    public static Boolean resultCode(String result) {
        boolean codeb = false;
        try {
            result = new JSONObject(result).getJSONObject("result").getString("code");
            if (result.equals("C0001")) {
                codeb = true;
            }
        } catch (Exception e) {
        }
        return codeb;
    }

    //code
    public static String resultCodes(String result) {
        try {

            result = new JSONObject(result).getJSONObject("result").getString("code");
        } catch (Exception e) {
        }
        return result;
    }

    //msg
    public static String resultMsg(String result) {
        try {
            result = new JSONObject(result).getJSONObject("result").getString("msg");
        } catch (Exception e) {
        }
        return result;
    }

    //result
    public static JSONObject resultResult(String result) {
        JSONObject resultj = null;
        try {
            resultj = new JSONObject(result).getJSONObject("result");
        } catch (Exception e) {
        }
        return resultj;
    }

    //response
    public static JSONObject resultResponse(String result) {
        JSONObject resultj = null;
        try {
            resultj = new JSONObject(result).getJSONObject("response");
        } catch (Exception e) {
        }
        return resultj;
    }

    //dataList
    public static JSONArray resultDataList(String result) {
        JSONArray resultj = null;
        try {
            resultj = new JSONObject(result).getJSONArray("dataList");
        } catch (Exception e) {
        }
        return resultj;
    }

    //success
    public static String resultSuccess(String success) {
        try {
            success = new JSONObject(success).getJSONObject("result").getString("success");
        } catch (Exception e) {
        }
        return success;
    }

    //jsonObject String
    public static String getString(JSONObject jsonObject, String nodrives) {
        String value = "";
        try {
            if (jsonObject.has(nodrives)) {//检测出是否存在该键值
                value = jsonObject.getString(nodrives);
                if (value.equals("null")) {
                    value = "";
                }
            }
        } catch (Exception e) {
        }
        return value;
    }

    //jsonObject String
    public static String getString(JSONObject jsonObject,String nodrive, String nodrives) {
        String value = "";
        try {
            if (jsonObject.has(nodrives)) {//检测出是否存在该键值
                value = jsonObject.getString(nodrives);
                if (value.equals("null")) {
                    value = "";
                }
                value=nodrive+value;
            }
        } catch (Exception e) {
        }
        return value;
    }

    //jsonObject String
    public static long getLong(JSONObject jsonObject, String nodrives) {
        long value = 0;
        try {
            if (jsonObject.has(nodrives)) {//检测出是否存在该键值
                value = jsonObject.getLong(nodrives);
            }
        } catch (Exception e) {
        }
        return value;
    }

    //jsonObject Int
    public static int getInt(JSONObject jsonObject, String nodrives) {
        int value = -100;
        try {

            if (jsonObject.has(nodrives)) {//检测出是否存在该键值
                value = jsonObject.getInt(nodrives);
            }
        } catch (Exception e) {
        }
        return value;
    }

    //jsonObject JSONArray
    public static JSONArray getJSONArray(JSONObject jsonObject, String dataList) {
        JSONArray value = null;
        try {
            if (jsonObject.has(dataList)) {//检测出是否存在该键值
                value = jsonObject.getJSONArray(dataList);
            }
        } catch (Exception e) {
        }
        return value;
    }

    //jsonObject JSONArray
    public static JSONObject getJSONArray(JSONArray jsonArray,int index) {
        JSONObject value = null;
        try {
            value=jsonArray.getJSONObject(index);
        } catch (Exception e) {
        }
        return value;
    }

}
